// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.
//
// ███╗   ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗  ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║   ██║   ██║   ██║██║     █████╗
// ██║╚██╗██║██║   ██║   ██║   ██║██║     ██╔══╝
// ██║ ╚████║╚██████╔╝   ██║   ██║╚██████╗███████╗
// ╚═╝  ╚═══╝ ╚═════╝    ╚═╝   ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch
{
	public sealed partial class StoredScript
	{
		[JsonInclude]
		[JsonPropertyName("lang")]
		public string Language { get; set; }

		[JsonInclude]
		[JsonPropertyName("options")]
		public Dictionary<string, string>? Options { get; set; }

		[JsonInclude]
		[JsonPropertyName("source")]
		public string Source { get; set; }
	}

	public sealed partial class StoredScriptDescriptor : SerializableDescriptorBase<StoredScriptDescriptor>
	{
		internal StoredScriptDescriptor(Action<StoredScriptDescriptor> configure) => configure.Invoke(this);
		public StoredScriptDescriptor() : base()
		{
		}

		private string LanguageValue { get; set; }

		private Dictionary<string, string>? OptionsValue { get; set; }

		private string SourceValue { get; set; }

		public StoredScriptDescriptor Language(string language)
		{
			LanguageValue = language;
			return Self;
		}

		public StoredScriptDescriptor Options(Func<FluentDictionary<string, string>, FluentDictionary<string, string>> selector)
		{
			OptionsValue = selector?.Invoke(new FluentDictionary<string, string>());
			return Self;
		}

		public StoredScriptDescriptor Source(string source)
		{
			SourceValue = source;
			return Self;
		}

		protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
		{
			writer.WriteStartObject();
			writer.WritePropertyName("lang");
			JsonSerializer.Serialize(writer, LanguageValue, options);
			if (OptionsValue is not null)
			{
				writer.WritePropertyName("options");
				JsonSerializer.Serialize(writer, OptionsValue, options);
			}

			writer.WritePropertyName("source");
			writer.WriteStringValue(SourceValue);
			writer.WriteEndObject();
		}
	}
}